package com.ztc.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.ztc.bean.StoreModel;

/**
 * @类名：StoreDao.java
 * @作者：李晓平
 * @时间：2018年7月25日 下午3:08:28
 * @描述：收藏Dao
 */
@Mapper
public interface StoreDao {

	/**
	 * 查询我的收藏
	 * @param store
	 * @return
	 */
	@Select("<script>"
			+ "select id,title from tab_store"
			+ " where 1=1"
			+ "<if test='store.userId!=null and store.userId!=\"\"'>"
			+ " and userId=#{store.userId}"
			+ "</if>"
			+ "<if test='store.authId!=null and store.authId!=\"\"'>"
			+ " and authId=#{store.authId}"
			+ "</if>"
			+ "<if test='store.projectId!=null and store.projectId!=\"\"'>"
			+ " and projectId=#{store.projectId}"
			+ "</if>"
			+ "<if test='store.title!=null and store.title!=\"\"'>"
			+ " and title like '%${store.title}%'"
			+ "</if>"
			+ "<if test='store.content!=null and store.content!=\"\"'>"
			+ " and content=#{store.content}"
			+ "</if>"
			+ "<if test='store.enterpriseId!=null and store.enterpriseId!=\"\"'>"
			+ " and enterpriseId=#{store.enterpriseId}"
			+ "</if>"
			+ " order by id"
			+ "</script>")
	public List<StoreModel> queryStoreList(@Param("store") StoreModel store);
	
	/**
	 * 查询单个收藏明细
	 * @param id
	 * @return
	 */
	@Select("select * from tab_store where id=#{id}")
	public StoreModel queryOneStore(@Param("id") int id);

	/**
	 * 添加收藏
	 * @param store
	 * @return
	 */
	@Insert("insert into tab_store(authId,projectId,userId,title,content,enterpriseId)"
			+ " values (#{store.authId},#{store.projectId},#{store.userId},#{store.title},#{store.content},#{store.enterpriseId})")
	public int addStore(@Param("store") StoreModel store);
	
	/**
	 * 删除收藏
	 * @param id
	 * @return
	 */
	@Delete("delete from tab_store where id=#{id}")
	public int deleteStore(@Param("id") int id);
}
